Ext.define('TongjiView', {
	extend : 'Ext.panel.Panel',
	id : 'TongjiView',
	title : '选题统计（按学生）',
	region : 'center',
	layout : 'border',
	iconCls: 'menu-cusLinkman',

	initComponent : function() {		
		this.searchPanel = new KE.SearchPanel({
					region : 'north',
					items : [{
								text : '姓名'
							}, {
								width : 120,
								name : 'Q_LIKES_fullname',
								xtype : 'textfield'								
							}, {
								xtype : 'button',
								text : '查询',
								scope : this,
								iconCls : 'btn-search',
								handler : this.search
							}, {
								xtype : 'button',
								text : '清空',
								scope : this,
								iconCls : 'reset',
								handler : this.reset
							}]
				});
		
		this.topbar = new Ext.Toolbar({
			items : [{
						iconCls : 'btn-mail_recipient',
						text : '指派题目',
						xtype : 'button',
						scope : this,
						handler : this.fenpei
					},'-', {
						iconCls : 'btn-doc',
						text : '导出审报表',
						xtype : 'button',
						scope : this,
						handler : this.exportWord
					}]
		});

		this.gridPanel = new KE.GridPanel({
			region : 'center',
			tbar : this.topbar,
			id : 'TongjiGrid',
			url : __ctxPath + "/byxt/listTongji.do",
			fields : ['userId','oid','name', 'subjectName', 'xuehao','teacherName'],
			columns : [{
						header : 'userId',
						dataIndex : 'userId',
						hidden:true
					},{
						header : 'oid',
						dataIndex : 'oid',
						hidden:true
					},{
						header : '学号',
						dataIndex : 'xuehao'
					},{
						header : '学生姓名',
						dataIndex : 'name'
					}, {
						header : '题目',
						dataIndex : 'subjectName',
						renderer: function(v) {
							if(v == null) {
								return "<span class='bg-danger'>该学生没有选题</span>";

							} else {
								return "<span class='bg-success'>" + v + "</span>";
							}
						}
					},{
						header : '老师',
						dataIndex : 'teacherName'
					}]
		});

		this.items = [this.searchPanel, this.gridPanel];
		this.callParent();
		this.gridPanel.on('rowdblclick', this.rowClick);
	},
	// 重置查询表单
	reset : function() {
		this.searchPanel.getForm().reset();
		Ext.each(this.searchPanel.query('combo'), function(c) {
			c.setValue('');
			c.setRawValue('');
		});
	},
	// 按条件搜索
	search : function() {
		$search({
			searchPanel : this.searchPanel,
			gridPanel : this.gridPanel
		});
	},
	fenpei : function() {
		var rec = $selectOne(this.gridPanel);
		if(!rec) return;		
		var me = this;
		SubjectSelector.getView2(
				function(ids, names) {
					$postAjax({
						scope: this,
						url: __ctxPath + '/byxt/addStudentYuXuan.do',
						params: {
							studentId:rec.userId,
							subjectId:ids	
						},
						callback: function() {
							me.gridPanel.getStore().reload();
						}
					});
				}, true,null).show();		
	},
	// 导出申报表
	exportWord : function() {
		var selRs = this.gridPanel.getSelectionModel().getSelection();
		if(selRs.length == 0) {
			Ext.ux.Toast.msg('操作信息', '请选择要操作的记录！');
			return false;
		}
		var userIds = [];
	 
		for(var i=0; i<selRs.length; i++) {
			userIds.push(selRs[i].data.userId);			
		}	
		
//		var rowData = this.gridPanel.selection.data;

		Ext.MessageBox.confirm('提示', '您确认要导出【选题申报】文档吗？', function (id) {
			if (id=='yes') {
				window.location.href = __ctxPath + '/byxt/exportWordYuXuan.do?userIds=' + userIds;
			}
		});
		
	}
	
	

});
